enable_testing()

#include(PrintAllVariables)
#print_all_variables()

cdata(READ data_files "${CMAKE_CURRENT_LIST_DIR}/CDataList.txt"
  GENERATE "${CMAKE_CURRENT_BINARY_DIR}/l1brsgen-data"
  VERBOSE
  TEST l1brsgen-data
  SAVE_DIR dataDir)

# add a test that creates the output directory
add_test(NAME "l1brsgen-output"
  WORKING_DIRECTORY ${dataDir}
  COMMAND mkdir -p output)

################################################################################
# l1brsgen PNG creation - Aqua
################################################################################
add_test(NAME "l1brsgen_A2008080195500.L1B_BRS_PNG-test"
    WORKING_DIRECTORY ${dataDir}
    COMMAND l1brsgen par=A2008080195500.L1B_BRS_PNG.par)

add_test(NAME "l1brsgen_A2008080195500.L1B_BRS_PNG-check"
    WORKING_DIRECTORY ${dataDir}
    COMMAND compare -metric AE -fuzz ${FUZZ} A2008080195500.L1B_BRS.png output/A2008080195500.L1B_BRS.png /dev/null )


################################################################################
#  l1brsgen HDF creation - Aqua
################################################################################
# modify the $ENV{OCTEST_TOLERANCE} for hdiff output

add_test(NAME "l1brsgen_A2008080195500.L1B_BRS-test"
    WORKING_DIRECTORY ${dataDir}
    COMMAND l1brsgen par=A2008080195500.L1B_BRS.par)

if(DEFINED ENV{OCTEST_TOLERANCE})
  set(TOLERANCE '')
  STRING(REGEX REPLACE "-T" "-p" TOLERANCE $ENV{OCTEST_TOLERANCE})
  add_test(NAME "l1brsgen_A2008080195500.L1B_BRS-check"
    WORKING_DIRECTORY ${dataDir}
    COMMAND compare_hdf4.py -G "Processing Time" ${TOLERANCE} A2008080195500.L1B_BRS.hdf output/A2008080195500.L1B_BRS.hdf)
else(DEFINED ENV{OCTEST_TOLERANCE})
  add_test(NAME "l1brsgen_A2008080195500.L1B_BRS-check"
    WORKING_DIRECTORY ${dataDir}
    COMMAND compare_hdf4.py -G "Processing Time" A2008080195500.L1B_BRS.hdf output/A2008080195500.L1B_BRS.hdf)
endif(DEFINED ENV{OCTEST_TOLERANCE})


################################################################################
#  l1brsgen HDF creation - 8bit Aqua
################################################################################
# modify the $ENV{OCTEST_TOLERANCE} for hdiff output

add_test(NAME "l1brsgen_A2008080195500.L1B_BRS.8bit-test"
    WORKING_DIRECTORY ${dataDir}
    COMMAND l1brsgen par=A2008080195500.L1B_BRS.8bit.par)

if(DEFINED ENV{OCTEST_TOLERANCE})
    set(TOLERANCE '')
    STRING(REGEX REPLACE "-T" "-p" TOLERANCE $ENV{OCTEST_TOLERANCE})
    add_test(NAME "l1brsgen_A2008080195500.L1B_BRS.8bit-check"
        WORKING_DIRECTORY ${dataDir}
        COMMAND compare_hdf4.py -G "Processing Time" ${TOLERANCE} A2008080195500.L1B_BRS.8bit.hdf output/A2008080195500.L1B_BRS.8bit.hdf)
else(DEFINED ENV{OCTEST_TOLERANCE})
    add_test(NAME "l1brsgen_A2008080195500.L1B_BRS.8bit-check"
        WORKING_DIRECTORY ${dataDir}
        COMMAND compare_hdf4.py -G "Processing Time" A2008080195500.L1B_BRS.8bit.hdf output/A2008080195500.L1B_BRS.8bit.hdf)
endif(DEFINED ENV{OCTEST_TOLERANCE})



################################################################################
# l1mapgen PPM creation - Aqua
################################################################################

add_test(NAME "l1mapgen_A2008080195500.L1B_MAP_PNM-test"
    WORKING_DIRECTORY ${dataDir}
    COMMAND l1mapgen par=A2008080195500.L1B_MAP_PNM.par)

add_test(NAME "l1mapgen_A2008080195500.L1B_MAP_PNM-check"
    WORKING_DIRECTORY ${dataDir}
    COMMAND compare -metric AE -fuzz ${FUZZ} A2008080195500.L1B_MAP.ppm output/A2008080195500.L1B_MAP.ppm output/A2002365234500.L1B_MAP.diff.ppm )

################################################################################
# l1mapgen PNG creation - Aqua
################################################################################
add_test(NAME "l1mapgen_A2008080195500.L1B_MAP_PNG-test"
    WORKING_DIRECTORY ${dataDir}
    COMMAND l1mapgen par=A2008080195500.L1B_MAP_PNG.par)

add_test(NAME "l1mapgen_A2008080195500.L1B_MAP_PNG-check"
    WORKING_DIRECTORY ${dataDir}
    COMMAND compare -metric AE -fuzz ${FUZZ} A2008080195500.L1B_MAP.png output/A2008080195500.L1B_MAP.png output/A2002365234500.L1B_MAP.diff.png )

################################################################################
# l1mapgen GeoTIFF creation - Aqua
################################################################################
add_test(NAME "l1mapgen_A2008080195500.L1B_MAP_TIF-test"
    WORKING_DIRECTORY ${dataDir}
    COMMAND l1mapgen par=A2008080195500.L1B_MAP_TIF.par)

add_test(NAME "l1mapgen_A2008080195500.L1B_MAP_TIF-check"
    WORKING_DIRECTORY ${dataDir}
    COMMAND compare -metric AE -fuzz ${FUZZ} A2008080195500.L1B_MAP.tiff output/A2008080195500.L1B_MAP.tiff output/A2002365234500.L1B_MAP.diff.tiff)

################################################################################
# l1mapgen PNG creation - SeaWiFS
################################################################################
add_test(NAME "l1mapgen_S2002079071209.L1A_GAC_MAP_PNG-test"
    WORKING_DIRECTORY ${dataDir}
    COMMAND l1mapgen par=S2002079071209.L1A_GAC_MAP_PNG.par)

add_test(NAME "l1mapgen_S2002079071209.L1A_GAC_MAP_PNG-check"
    WORKING_DIRECTORY ${dataDir}
    COMMAND compare -metric AE -fuzz ${FUZZ} S2002079071209.L1A_GAC_MAP.png output/S2002079071209.L1A_GAC_MAP.png output/S1998199173926.L1A_GAC_MAP.diff.png )
